package org.ruanjj.streamapi;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    @org.junit.Test
    public void test1(){
        User1 us = new User1("Mary",19);
        System.out.println(us.age());
        us.printUser();

        Color red = Color.RED;
        System.out.println(red.name());
    }
    public static void main(String[] args) {
        int[] a =  new int[]{1,2,3,4,5,6};
        List<Integer> res = new ArrayList<>();
        Arrays.stream(a).filter(n -> n>2).forEach(System.out::println);
        Arrays.stream(a).limit(2).forEach(System.out::println);
        Arrays.stream(a).skip(2).forEach(n->res.add(n));
        Arrays.stream(a).sorted().forEach(System.out::println);
        System.out.println(Arrays.stream(a).reduce(Integer::sum).getAsInt());


        List<User1> users = new ArrayList();
        users.add(new User1("Tom",12));
        users.add(new User1("Tony",16));
        users.add(new User1("Mary",13));
        users.add(new User1("Deny",8));
        users.add(new User1("Leo",9));
        users.add(new User1("Celia",22));
        users.add(new User1("Celia",22));
        users.add(new User1("Celia",22));
        users.add(new User1("Celia",22));
        users.add(new User1("Celia",22));
       /* users.stream().map(User::getName).forEach(System.out::println);
        users.stream().distinct().forEach(System.out::println);
        users.stream().distinct().sorted((o1, o2) -> o2.compareTo(o1)).forEach(System.out::println);
        System.out.println(users.stream().distinct().allMatch(t -> t.getAge() < 23));
        System.out.println(users.stream().distinct().anyMatch(t -> t.getAge() < 3));
        System.out.println(users.stream().distinct().findFirst().get());*/
        List<Integer> ages = users.stream().distinct().map(user1->user1.age()).sorted().collect(Collectors.toList());
        ages.forEach(System.out::println);

        //2.进行数组创建
        Arrays.stream(new int[]{1,2,3,4,5,6});

    }
}
